package com.adt.studioms.om;

import java.util.ArrayList;
import java.util.List;

import com.asao.baseware.core.om.Entity;

public class Service extends Entity {
    Task task;
    PhotoSize photoSize;
    long price;
    List<ServiceSnapshot> snapshots;

    public Service() {
        snapshots = new ArrayList<ServiceSnapshot>();
    }
    
    public Task getTask() {
        return task;
    }

    public void setTask(Task task) {
        this.task = task;
    }

    public PhotoSize getPhotoSize() {
        return photoSize;
    }

    public void setPhotoSize(PhotoSize photoSize) {
        this.photoSize = photoSize;
    }

    public long getPrice() {
        return price;
    }

    public void setPrice(long price) {
        this.price = price;
    }

    public List getSnapshots() {
        return snapshots;
    }

    public void setSnapshots(List snapshots) {
        this.snapshots = snapshots;
    }
    
    public void addSnapshot(ServiceSnapshot snapshot) {
        if (snapshot != null) {
            snapshots.add(snapshot);
            snapshot.setService(this);
        }
    }

    public void removeSnapshot(ServiceSnapshot snapshot) {
        if (snapshot != null) {
            snapshots.remove(snapshot);
            snapshot.setService(null);
        }
    }
    
    public ServiceSnapshot createSnapshot() {
        ServiceSnapshot snapshot = new ServiceSnapshot(this);
        addSnapshot(snapshot);
        
        return snapshot;
    }
    
    public ServiceSnapshot getLastSnapshot() {
        int size = countSnapshot();
        if (size<=0)
            return createSnapshot();
        
        return snapshots.get(size-1);
    }
    
    public ServiceSnapshot getSnapshot(int index) {
        return snapshots.get(index);
    }
    
    public int countSnapshot() {
        return snapshots.size();
    }
}
